<!-- loginRelease.html -->
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
	<title>登录</title>

	<link href="css/mui.min.css" rel="stylesheet" />
	<link rel="stylesheet" href="./css/CFNetPP_Base.css">
	<style type="text/css" media="screen">
	
		.login_content_div{
			padding: 64px 30px 0 30px;
				height: 100%;
		}
		.logo_div{
			text-align: center;
		}
		.logo_img{
			width: 44px;
			height: 44px;
		}
		.logo_title{
			font-size: 30px;
			color: #454545;
			margin: 12px 0 0 0;
			padding-bottom: 40px;
		}
		.input_text{
			width: 100%;
			height: 40px;
			margin-top: 10px;
			border:1px solid #454545;
		}
		.user_type_select{
			margin-top: 10px;
			width: 100px;
			height: 40px;
			border:1px solid #454545;
		}
		.login_btn{
			margin-top: 20px;
			color: white;
			font-size: 18px;
			background-color: #fe9901;
		}
		.mui-btn-block{
			padding: 10px 0;
		}
		.mui-input-row label{
			width: 14%;
			padding: 8px 0;
			line-height: 1em;
		}
		.mui-input-row label~input, .mui-input-row label~select, .mui-input-row label~textarea{
			width: 86%;
		}
		.mui-input-row{
			border-bottom: 1px solid #d9d9d9;
			height: 48px;
			margin-top: 20px;
		}
		/*.mui-icon-eye:before{
			color: #fe9901;
		}*/
		.text_input_icon{
			height: 24px;
		}
		.password_about_div{
			padding: 10px 0;
			overflow: auto;
		}
		.left_div{
			float: left;
			width: 50%;
			height: 34px;
		}
		.right_div{
			float: right;
			width: 50%;
			height: 34px;
		}
		.diy_input_row{
			border:none;
			margin: 0;
			height: 34px;
		}
		.mui-checkbox.mui-left label{
			padding: 0;
		}
		.mui-checkbox.mui-left input[type=checkbox], .mui-radio.mui-left input[type=radio] {
			left: 0;
		}
		.mui-checkbox input[type=checkbox]:before, .mui-radio input[type=radio]:before{
			color: #d9d9d9;
			font-size: 24px;
		}
		.forget_password_span{
			float: right;
			line-height: 34px;
		}
		.mui-checkbox input[type=checkbox]:checked:before, .mui-radio input[type=radio]:checked:before{
			color: #18b4ed;
		}
		html,body{
			background-color: white;
			height: 100%;
			
		}
		.div_btton{
	      width:100%;
		  text-align: center; 
		  position: absolute; 
		
         bottom: 5px; 
    }
	</style>
</head>
<body>
	<div class="login_content_div">
		<div class="logo_div">
			<img class="logo_img" src="image/logo.png" alt="">
			<p class="logo_title">长风网</p>
		</div>

		<div class="mui-input-row">
			<label><img class="text_input_icon" src="image/icon_yonghuming.png" alt=""></label>
			<input id="account_input" type="email" class="mui-input-clear" placeholder="请输入用户名">
		</div>
		<div class="mui-input-row mui-password">
			<label><img class="text_input_icon" src="image/icon_mima.png" alt=""></label>
			<input id="password_input" type="password" class="mui-input-clear" placeholder="请输入密码" onkeypress="onKeyClick()">
		</div>

		<div class="password_about_div">
			<div class="left_div">
				<div class="mui-input-row mui-checkbox mui-left diy_input_row">
					<label class="base_grey base_tag_font" style="width: 60px; margin: 11px 28px;" for="remember_password">记住密码</label>
					<input id="remember_password" name="checkbox" value="Item 1" type="checkbox" >
				</div>
			</div>
			<div id="forget_password" class="right_div base_grey base_tag_font">
				<span class="forget_password_span">
					<!-- <span id="to_regis">注册 | </span> -->
					<span id="to_forget_password">忘记密码?</span>
				</span>
			</div>
		</div>
		<button type="button" class="mui-btn mui-btn-warning mui-btn-block login_btn" onclick="loginClick()">登录</button>

	</div>
	
	<div class="div_btton">
		<span id="to_regis">注册 </span>
	</div>
</body>
<script type="text/javascript" src="script/api.js"></script>
<script type="text/javascript" src="script/jquery.min.js"></script>
<script type="text/javascript" src="script/mui.min.js"></script>
<script type="text/javascript" src="script/MD5.js"></script>
<script type="text/javascript" src="script/requestTool.js"></script>
<script type="text/javascript">
	mui.init();
	var registrationid = '';
	apiready = function(){

	    setupAccountPWD();
	    setupForgetPWD();
	    

	}

	function prepareData(){
		var loginStatus = $api.getStorage('cfnetppLoginStatus');
		if (loginStatus == 1) {
			jumpToNextPage();
		}
	}
	//准备创建表
	function prepareDB(){
		// createTables(function(ret){});
		// ajpush = api.require('ajpush');
		// //初始化极光推送
  //   	ajpush.init(function(ret) {
		//     if (ret && ret.status){
		//     	ajpush.getRegistrationId(function(ret) {
		// 		    registrationid = ret.id;
		// 		    alert(registrationid);
		// 		});
		//     }
		// });
	}
	function setupForgetPWD(){
		$('#to_forget_password').click(function(){
			api.openWin({useWKWebView:true,
			    name: 'forgetpassword',
			    url: 'forgetpassword.html',
			    vScrollBarEnabled: false,
				hScrollBarEnabled: false
			});
		});
		$('#to_regis').click(function(){
			api.openWin({useWKWebView:true,
			    name: 'RegisterController',
			    url: 'RegisterController.html',
			    vScrollBarEnabled: false,
				hScrollBarEnabled: false
			});
		});
	}
	function loginClick(){
		var account = $('#account_input').val();
		var password = $('#password_input').val();
		if (account.length == 0 || password.length == 0) {
			api.toast({
			    msg: '账户名和密码不能为空!',
			    duration: 2000,
			    location: 'bottom'
			});
			return;
		}
		api.showProgress({
		    style: 'default',
		    animationType: 'fade',
		    title: '正在登录',
		    text: '请稍候...',
		    modal: true
		});
		var params = {
			account : account,
			password : MD5(password)
		}; 
		if (registrationid != '') {
			params = {
				account : account,
				password : MD5(password),
				registrationid : registrationid
			}; 
		}
		cfnetppPOST(urlLogin,
			params,
			false,
			function(data, status){
				api.hideProgress();
				if (status == 'success') {
					if (data.status == 1) {
						rememberAccountPWD();
						loginSucceed(data.json);
						saveUserType(data.json);
						jumpToNextPage();
					}else{
						var errorStatus = data.message;
						var msgString = '';
						switch(errorStatus){
							case 1:
							case 2:
							msgString = '账号或密码错误';
							break;
							case 3:
							msgString = '您还没有注册实习平台';
							break;
							case 4:
							msgString = '您所属集团暂未开通实习平台';
							break;
							case 6:
							msgString = '暂不支持管理员登陆';
							break;
							case 9:
							msgString = '您所在的集团未到开始使用时间';
							break;
							case 10:
							msgString = '您所在的集团已过期';
							break;
							case 11:
							msgString = '暂不支持该用户类型登陆';
							break;
							default:
							msgString = '登录失败';
						}
						api.toast({
						    msg: msgString
						});
					}
				}else{
					api.toast({
					    msg: '网络异常!'
					});
				}
			});
	}
	function loginSucceed(data){

		//计算总流量每次登陆清空为0
		// $api.setStorage('volumeOfFlow', '0');

		$api.setStorage('cfnetppuid', data.uid);
		$api.setStorage('cfnetppjid', data.jid);
		$api.setStorage('cfnetppjxid', data.jxid);
		$api.setStorage('cfnetppusername', data.username);
		$api.setStorage('cfnetpprealname', data.realname);
		var opentype = data.opentype;
		if (opentype == 'null') {
			opentype == 1;
		}
		$api.setStorage('cfnetppopentype', data.opentype);//打开0周报,1日报,2日报周报都有
		//用户类型为师傅时存储
		if (data.usertype == 4) {
			$api.setStorage('cfnetppjid', data.cid);//企业id
			$api.setStorage('cfnetpprealname', data.mastername);//师傅姓名
			$api.setStorage('cfnetppcid', data.cid);//企业id
			$api.setStorage('cfnetppmastername', data.mastername);//师傅姓名
			$api.setStorage('cfnetppmasterphone', data.masterphone);//师傅电话
			$api.setStorage('cfnetppposition', data.position);//职位
			$api.setStorage('cfnetppcorpname', data.corp_comname);//企业名称
		}
		// $api.setStorage('cfnetppuserschool', data.userschool);
		// $api.setStorage('cfnetppusercoll', data.usercoll);
		//todo
		var userprofile = data.userprofile;
		if (userprofile == '' || userprofile == null || userprofile == undefined) {
			userprofile = 'image/default_user_icon.png';
		}
		$api.setStorage('cfnetppusericon', userprofile);
		//记录登陆状态
		$api.setStorage('cfnetppLoginStatus', 1);
		if (data.isperfected == 0) {//未完善个人信息
			setTimeout(function(){
				sendUserInfoNotifi();
			}, 1000);
			// sendUserInfoNotifi();
		}
		api.sendEvent({//发送登陆成功通知
		    name: 'loginSucceedNotifi'
		});
	}
	//发送用户完善信息通知
	function sendUserInfoNotifi(){
		cfnetppPOST(urlUserinfoNotifi,{uid: $api.getStorage('cfnetppuid')},false,function(data, status){});
	}
	function saveUserType(data){
		var usertype = data.usertype;
		$api.setStorage('userType', usertype);
	}
	function jumpToNextPage(){
		var usertype = $api.getStorage('userType');
		if (usertype == 0) {//学生
			api.toast({
			    msg: '登录成功'
			});

			var pagename = '';
			var pageurl = '';
//			if (studyType != '') {
//				pagename = 'TrainStudentStudyIndex';
//				pageurl = 'TrainStudentStudyIndex.html';
//			}else{
				pagename = 'index';
				pageurl = 'index.html';
//			}
			api.openWin({useWKWebView:true,
			    name: pagename,
			    url: pageurl,
			    animation: {
			    	type: "none",                //动画类型（详见动画类型常量）
				    subType: "from_right",       //动画子类型（详见动画子类型常量）
				    duration: 0  
			    },
			    slidBackEnabled: false
			});
		}else if(usertype == 1){//教师
			api.toast({
			    msg: '登录成功'
			});
			api.openWin({useWKWebView:true,
			    name: 'TrainTeacherIndex',
			    url: 'TrainTeacherIndex.html',
			    animation: {
			    	type: "none",                //动画类型（详见动画类型常量）
				    subType: "from_right",       //动画子类型（详见动画子类型常量）
				    duration: 0  
			    },
			    slidBackEnabled: false
			});
		}else if(usertype == 4){//师傅
			api.toast({
			    msg: '登录成功'
			});
			api.openWin({useWKWebView:true,
			    name: 'TrainMasterIndex',
			    url: 'TrainMasterIndex.html',
			    animation: {
			    	type: "none",                //动画类型（详见动画类型常量）
				    subType: "from_right",       //动画子类型（详见动画子类型常量）
				    duration: 0  
			    },
			    slidBackEnabled: false
			});
		}else{
			api.toast({
			    msg: '暂不支持非学生、教师或师傅的用户类型'
			});
		}
		//设置密码
		setupPWD();
	}
	function setupAccountPWD(){
		//设置账号
		$('#account_input').val($api.getStorage('cfnetppaccount'));
		//设置密码
		setupPWD();
	}
	function setupPWD(){
		//设置密码
		var remPWDStatus = $api.getStorage('remPWDStatus');
		if (remPWDStatus == 'true') {
			$('#remember_password').attr('checked', 'true');
			$('#password_input').val($api.getStorage('cfnetpppassword'));
		}else{
			$('#password_input').val('');
		}
	}
	function rememberAccountPWD(){
		//记录账号
		$api.setStorage('cfnetppaccount', $('#account_input').val());
		//记录密码
		var remPWDStatus = $('#remember_password').is(':checked');
		if (remPWDStatus == true) {
			$api.setStorage('cfnetpppassword', $('#password_input').val());
			$api.setStorage('remPWDStatus', 'true');
		}else{
			$api.setStorage('remPWDStatus', 'false');
		}
	}
	function onKeyClick(){
		if(event.keyCode==13) {
			loginClick();
		}
	}
	
</script>
</html>